/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.common.e;

import android.content.Context;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.common.i.c;
import com.qihoo.gamecenter.sdk.common.i.f;
import com.qihoo.gamecenter.sdk.common.i.k;
import com.qihoo.gamecenter.sdk.common.i.s;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class a {
    private static final boolean a = ("PAY".toUpperCase().contains("PAY"))
            && (!("PAY".toUpperCase().contains("SOCIAL")));

    public static String a(Map paramMap, int paramInt) {
        return a(paramMap, paramInt, "json", true);
    }

    private static String b(Map paramMap, int paramInt, String paramString, boolean paramBoolean) {
        if ((paramMap == null) || (paramMap.size() <= 0))
            return null;
        if (paramInt < 0)
            return null;
        TreeMap localTreeMap = new TreeMap(new Comparator() {
            public int a(String paramString1, String paramString2) {
                return paramString1.compareTo(paramString2);
            }
        });
        localTreeMap.putAll(paramMap);
        String str1 = a(paramInt);
        localTreeMap.put("from", str1);
        localTreeMap.put("v", s.a());
        if (paramBoolean)
            localTreeMap.put("res_mode", "1");
        if (!(TextUtils.isEmpty(paramString)))
            localTreeMap.put("format", paramString);
        StringBuilder localStringBuilder1 = new StringBuilder();
        StringBuilder localStringBuilder2 = new StringBuilder();
        Set localSet = localTreeMap.keySet();
        Iterator localIterator = localSet.iterator();
        String str2 = null;
        String str3 = null;
        String str4 = null;
        StringBuilder localStringBuilder3 = null;
        try {
            while (localIterator.hasNext()) {
                str2 = (String) localIterator.next();
                str3 = (String) localTreeMap.get(str2);
                str4 = URLEncoder.encode(str3, "UTF-8");
                localStringBuilder3 = new StringBuilder(str2).append('=');
                localStringBuilder2.append(new StringBuilder(localStringBuilder3).append(str3));
                localStringBuilder1.append(new StringBuilder(localStringBuilder3).append(str4)).append('&');
            }
        } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
            c.b("QucIntfUtil", new Object[] { localUnsupportedEncodingException.toString() });
            return null;
        }
        localStringBuilder2.append(c());
        String str5 = k.a(localStringBuilder2.toString());
        localStringBuilder1.append("sig=").append(str5);
        c.a("TRACE_ACCOUNT", new Object[] { "Unsiged=", localStringBuilder2.toString() });
        c.a("TRACE_ACCOUNT", new Object[] { "RawParams=", localStringBuilder1.toString() });
        return b(localStringBuilder1.toString(), str1);
    }

    public static String a(Map paramMap, int paramInt, String paramString, boolean paramBoolean) {
        return b(paramMap, paramInt, paramString, true);
    }

    public static String a(String paramString1, String paramString2) {
        c.a("QucIntfUtil", new Object[] { "url=", paramString1 });
        if (a(paramString1))
            return b(paramString2);
        return paramString2;
    }

    private static boolean a(String paramString) {
        if (TextUtils.isEmpty(paramString))
            return false;
        if (!(paramString.startsWith("https://passport.360.cn/api.php?parad=")))
            return false;
        int i = paramString.indexOf("https://passport.360.cn/api.php?parad=")
                + "https://passport.360.cn/api.php?parad=".length();
        int j = paramString.lastIndexOf("&from=");
        if ((i > 0) && (j > 0) && (j > i)) {
            String str = paramString.substring(i, j);
            c.a("QucIntfUtil", new Object[] { "params=", str });
            str = f.b(str, a());
            c.a("QucIntfUtil", new Object[] { "params=", str });
            if (str.contains("&res_mode=1&"))
                return true;
        }
        return false;
    }

    private static String b(String paramString) {
        if (TextUtils.isEmpty(paramString))
            return paramString;
        return f.d(paramString, a());
    }

    public static String a(Context paramContext) {
        int i = s.q(paramContext);
        return a(i);
    }

    public static String a(int paramInt) {
        if (paramInt > 0)
            return b() + paramInt;
        return b() + "default";
    }

    private static String b(String paramString1, String paramString2) {
        String str1 = null;
        String str2 = f.a(paramString1, a());
        if (!(TextUtils.isEmpty(str2))) {
            str1 = "https://passport.360.cn/api.php?parad=" + str2 + "&from=" + paramString2;
            c.a("QucIntfUtil", new Object[] { "passportUrl=", str1 });
        }
        return str1;
    }

    private static String b() {
        return ((a) ? "mpc_open_ms_" : "mpc_yxhezi_and_");
    }

    public static String a() {
        return ((a) ? "2a9u8q4y" : "u72g3fds");
    }

    private static String c() {
        return ((a) ? "78ae0wq1h" : "13a22fc0a");
    }
}